package com.hs.dnms.action.produce;
 
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.hs.core.action.BaseAction;
import com.hs.core.db.DBMgr;
@Controller  
public class ProduceController  extends BaseAction {
    /**
	 * 
	 */
	private static final long serialVersionUID = -354434172898440670L;
	private static final Logger logger = Logger.getLogger(ProduceController.class);
//	private IRoleService roleService;
//	@Autowired  
//	public void setRoleService(IRoleService roleService) {
//		this.roleService = roleService;
//	}
	 /**
	  * 查询主页面
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	  * @throws ServletException
	  * @throws IOException
	  */
	 @RequestMapping(value="/produce/waitProlist.do", method = RequestMethod.GET)   
     public ModelAndView waitProlist(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws ServletException, IOException {
         
		 return new ModelAndView("app/search/main",modelMap);
		 
	 } 
	 /**
	  * 原文加工
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	  * @throws ServletException
	  * @throws IOException
	  */
	 @RequestMapping(value="/produce/pictureProduce.do", method = RequestMethod.GET)   
     public ModelAndView pictureProduce(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws ServletException, IOException {
         
		 return new ModelAndView("app/produce/pictureproduce",modelMap);
		 
	 }
	 /**
	  * 图片上传框架页面
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	  * @throws ServletException
	  * @throws IOException
	  */
	 @RequestMapping(value="/produce/pictureFrame.do", method = RequestMethod.GET)   
     public ModelAndView pictureFrame(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws ServletException, IOException {
         
		 return new ModelAndView("app/produce/pictureframe",modelMap);
		 
	 }
	 /**
	  * 图片上传主页面
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	  * @throws ServletException
	  * @throws IOException
	  */
	 @RequestMapping(value="/produce/pictureIndex.do", method = RequestMethod.GET)   
     public ModelAndView pictureIndex(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws ServletException, IOException {
         
		 return new ModelAndView("app/produce/pictureupload",modelMap);
		 
	 }
	
	 /**
	  * 图片阅读页面
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	  * @throws ServletException
	  * @throws IOException
	  */
	 @RequestMapping(value="/produce/pictureRead.do", method = RequestMethod.GET)   
     public ModelAndView pictureRead(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws ServletException, IOException {
         
		 return new ModelAndView("app/produce/pictureread",modelMap);
		 
	 }
	 /**
	  * 读取现代疾病名称
	  * @param request
	  * @param response
	  * @param modelMap
	  * @return
	  * @throws ServletException
	  * @throws IOException
	  */
	 @RequestMapping(value="/produce/readModernDis.do", method = RequestMethod.GET)   
     public ModelAndView readModernDis(HttpServletRequest request,
				HttpServletResponse response,ModelMap modelMap) throws ServletException, IOException {
         String keyword = request.getParameter("q");
         String distype = request.getParameter("distype");
         StringBuffer dissql = new StringBuffer("select * from dnms_modern_dis where 1=1");
         if(null != keyword && !"".equals(keyword)){
        	 dissql.append(" and disname like'%");
        	 dissql.append(keyword);
        	 dissql.append("%'");
         }
         DBMgr dbo = this.getDbo(request);
         List disList = dbo.queryList(dissql.toString(), null);
         String jason = "[";
         for(int i=0; i<disList.size(); i++){
        	 Map onedis = (Map)disList.get(i);
        	 String disid = onedis.get("id") + "";
        	 String disname = (String)onedis.get("disname");
        	 if(i==0){
        		 jason += "{id:\""+disid+"\",modendis:\""+disname+"\"}";
        	 }else{
        		 jason += ",{id:\""+disid+"\",modendis:\""+disname+"\"}";
        	 }
         }
         jason += "]";
         System.out.println("jason::::" + jason);
         response.setCharacterEncoding("UTF-8");
         response.setContentType("application/json");
         PrintWriter out = response.getWriter();
	     out.print(jason);
	     out.flush();
	     out.close();
	     //return new ModelAndView("app/produce/dataPro",modelMap);
		 return null;
	 }
}
